import 'dart:developer';
import 'dart:ui' as ui show BoxHeightStyle, BoxWidthStyle;

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';

/// <summary>
/// todo: 自定义输入框
/// author：zwb
/// dateTime：2021/7/26 10:36
/// filePath：lib/widgets/rong_input.dart
/// desc:
/// <summary>
///
Widget textField({
  Key? key,
  TextEditingController? controller,
  FocusNode? focusNode,
  InputDecoration? decoration ,
  TextInputType? keyboardType,
  TextInputAction? textInputAction,
  TextCapitalization textCapitalization : TextCapitalization.none,
  TextStyle? style,
  StrutStyle? strutStyle,
  TextAlign textAlign : TextAlign.start,
  TextAlignVertical? textAlignVertical,
  TextDirection? textDirection,
  bool readOnly : false,
  ToolbarOptions? toolbarOptions,
  bool? showCursor,
  bool autofocus : false,
  obscuringCharacter : '•',
  bool obscureText : false,
  bool autocorrect : true,
  SmartDashesType? smartDashesType,
  SmartQuotesType? smartQuotesType,
  bool enableSuggestions : true,
  int? maxLines,
  int? minLines,
  bool expands : false,
  int? maxLength,
  bool maxLengthEnforced : true,
  Function(String)? onChanged,
  VoidCallback? onEditingComplete,
  Function(String)? onSubmitted,
  AppPrivateCommandCallback? onAppPrivateCommand,
  List<TextInputFormatter>? inputFormatters,
  bool? enabled,
  double? cursorWidth : 2.0,
  double? cursorHeight,
  Radius? cursorRadius,
  Color? cursorColor,
  ui.BoxHeightStyle selectionHeightStyle : ui.BoxHeightStyle.tight,
  ui.BoxWidthStyle selectionWidthStyle : ui.BoxWidthStyle.tight,
  Brightness? keyboardAppearance,
  EdgeInsets scrollPadding : const EdgeInsets.all(20.0),
  DragStartBehavior dragStartBehavior : DragStartBehavior.start,
  bool enableInteractiveSelection : true,
  Function()? onTap,
  MouseCursor? mouseCursor,
  InputCounterWidgetBuilder? buildCounter,
  ScrollController? scrollController,
  ScrollPhysics?  scrollPhysics,
  Iterable<String> ? autofillHints,
  String? restorationId,
  bool? isLeft,
  bool? isRight,
  Color? bgColor,
  double? height,
  EdgeInsetsGeometry? contentPadding,
  String? hintText,
  double? circular,
  Widget? icon,
  InputBorder? border,
  BoxBorder? boxBorder,
  Widget? suffixIcon,
  Widget? prefixIcon,
  TextStyle? hintStyle,
  Alignment? alignment,
  EdgeInsetsGeometry? boxPadding,
}) {
  return InkWell(
    onTap: onTap ?? null,
    child: Container(
      decoration: BoxDecoration(
        color: bgColor ?? Color.fromRGBO(0, 0, 0, 0.04),
        border: boxBorder,
        borderRadius: BorderRadius.circular(circular ?? 20),
      ),
      alignment: alignment ?? Alignment.center,
      height: height == null || height < 35.0 ? 35 : height,
      padding: boxPadding,
      child: TextField(
        obscureText: obscureText,
        focusNode: focusNode,
        controller: controller,
        textAlign: textAlign,
        enabled: enabled,
        maxLength: maxLength,
        maxLines: maxLines,
        textInputAction: textInputAction,
        obscuringCharacter: obscuringCharacter,
        cursorColor: cursorColor ?? Color.fromRGBO(66, 133, 244, 1.0),
        // 对其 微调TextStyle的height 和 contentPadding
        style: style ?? TextStyle(height: 1.4,fontSize: 16,color: Colors.black87),
        inputFormatters: inputFormatters,
        decoration: InputDecoration(
            icon: icon,
            hintText: hintText,
            hintStyle: hintStyle,
            suffixIcon: suffixIcon,
            prefixIcon: prefixIcon,
            contentPadding: contentPadding ?? EdgeInsets.symmetric(vertical: 0,horizontal: 10),
            counterText: "",
            isCollapsed: true,
            border: InputBorder.none
        ),
        readOnly: readOnly,
        onChanged: onChanged,
        onSubmitted: onSubmitted,
        textAlignVertical: TextAlignVertical.center,
        keyboardType: keyboardType ?? TextInputType.text ,
        onTap: (){
          if(onTap!=null) onTap();
          log("${keyboardType ?? TextInputType.text}",name: "输入框");
        },
      ),
    ),
  );
}
